package com.jstyle.jclifexd.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import com.jstyle.jclifexd.R;


public class HelpAdapter extends BaseExpandableListAdapter {

	private String[] arrayTitle;
	private String[] arrayText;
	private LayoutInflater inflater;

	public HelpAdapter(Context context, String[] arrayTitle, String[] arrayText) {
		this.arrayText = arrayText;
		this.arrayTitle = arrayTitle;
		this.inflater = LayoutInflater.from(context);

	}

	@Override
	public int getGroupCount() {
		// TODO Auto-generated method stub
		return arrayTitle.length;
	}

	@Override
	public int getChildrenCount(int groupPosition) {
		// TODO Auto-generated method stub
		return 1;
	}

	@Override
	public String getGroup(int groupPosition) {
		// TODO Auto-generated method stub
		return arrayTitle[groupPosition];
	}

	private int checkedItem = -1;

	public void setCheckItem(int postion) {
		
			checkedItem = postion;
			notifyDataSetChanged();
		
	}

	@Override
	public String getChild(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return arrayText[childPosition];
	}

	@Override
	public long getGroupId(int groupPosition) {
		// TODO Auto-generated method stub
		return groupPosition;
	}

	@Override
	public long getChildId(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return childPosition;
	}

	@Override
	public boolean hasStableIds() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public View getGroupView(final int groupPosition, boolean isExpanded,
                             View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ParentViewHolder parentViewHolder = null;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.item_helpparent, null);
			parentViewHolder = new ParentViewHolder();
			parentViewHolder.tv_parent = (TextView) convertView
					.findViewById(R.id.tv_item_helpparent);
			convertView.setTag(parentViewHolder);
		} else {
			parentViewHolder = (ParentViewHolder) convertView.getTag();
		}

		parentViewHolder.tv_parent.setText(arrayTitle[groupPosition]);
		return convertView;
	}

	public class ParentViewHolder {
		public TextView tv_parent;
	}

	public class ChildViewHolder {
		public TextView tv_child;
	}

	@Override
	public View getChildView(int groupPosition, int childPosition,
                             boolean isLastChild, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ChildViewHolder parentViewHolder = null;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.item_helpchild, null);
			parentViewHolder = new ChildViewHolder();
			parentViewHolder.tv_child = (TextView) convertView
					.findViewById(R.id.tv_item_helpchild);
			convertView.setTag(parentViewHolder);
		} else {
			parentViewHolder = (ChildViewHolder) convertView.getTag();
		}
		parentViewHolder.tv_child.setText(arrayText[groupPosition]);
		return convertView;
	}

	@Override
	public boolean isChildSelectable(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return false;
	}

}
